package com.zlx.guguanjia.controller;

import com.zlx.guguanjia.entity.Result;
import com.zlx.guguanjia.entity.SysRole;
import com.zlx.guguanjia.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Author 周罗校
 * @Description
 * @ClassName RoleController
 * @date 2020.11.03 18:57:10
 * 该版权归周罗校所有，最终解释权以官方为准
 */
@RestController
@RequestMapping("/manager/role")
public class SysRoleController {
    @Autowired
    private SysRoleService service;

    @GetMapping("getAllRole")
    public Result getAllRole(){
        return new Result(service.selectAll());
    }

    @GetMapping("selectPage/{start}/{pageSize}")
    public Result selectPage(@PathVariable("start") int start,@PathVariable("pageSize") int pageSize, @RequestParam Map<String,Object> map){
        return new Result(service.selectPage(start,pageSize,map));
    }

    @GetMapping("deleteBatch")
    public Result deleteBatch(@RequestParam("rid") Long rid,@RequestParam("ids") long[] ids){
        return new Result(true,"移除成功！",service.deleteBatch(rid,ids));
    }

    @GetMapping("insertBatch")
    public Result insertBatch(@RequestParam("rid") Long rid,@RequestParam("ids") Long[] ids){
        List<Long> longs = Arrays.asList(ids);
        return new Result(true,"添加成功！",service.insertBatch(rid, Arrays.asList(ids)));
    }

    @PutMapping("update")
    public Result update(@RequestBody Map<String,Object> params){
        return  new Result(true,"更新成功",service.updateByPrimaryKeySelective(params));
    }

    //逻辑删除
    @PutMapping("deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        SysRole role = new SysRole();
        role.setId(id);
        role.setDelFlag("1");
        //返回分页数据
        return new Result(true,"删除成功",service.updateByPrimaryKeySelective(role));
    }
}
